package com.shop.controller;


import com.shop.annotation.RequireRoles;
import com.shop.entity.SupplierCategory;
import com.shop.model.PageParam;
import com.shop.model.vo.Rsp;
import com.shop.service.SupplierCategoryService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * (SupplierCategory)表控制层
 *
 * @author makejava
 * @since 2020-11-21 10:12:51
 */
@Validated
@RestController
@RequestMapping("category")
@AllArgsConstructor
public class SupplierCategoryController {
    /*
     * 服务对象
     */
    private final SupplierCategoryService supplierCategoryService;




    /**
     * 修改类别名
     */
    @PostMapping("updateCategoryName")
    public Rsp updateCategoryName(@RequestBody SupplierCategory supplierCategory,
                                  @RequestHeader("userId")Integer userId){
        return Rsp.success(supplierCategoryService.updateCategoryName(supplierCategory,userId));
    }
    /**
     * 新增类别
     */
    @PostMapping("insertCategory")
    public Rsp insertCategory(@RequestBody SupplierCategory supplierCategory,
                              @RequestHeader("supplierId")Integer supplierId){
        return Rsp.success(supplierCategoryService.insertCategory(supplierCategory,supplierId));
    }

    /**
     * 删除类别
     *
     */
    @PostMapping("delCategory")
    public Rsp delCategory(@RequestBody  SupplierCategory supplierCategory){
        return Rsp.success(supplierCategoryService.delCategory(supplierCategory.getId()));
    }
    /**
     * @author Clh
     * @description 分页 模糊查询
     * @date  2020/11/26 9:36
     * @param pageParam
     * @return com.shop.model.vo.Rsp
    **/
    @PostMapping("searchSomeByPage")
    public Rsp searchSomeByPage(@RequestBody PageParam<SupplierCategory> pageParam,
                                @RequestHeader("supplierId")Integer supplierId){

        return Rsp.success(supplierCategoryService.searchSomeByPage(pageParam,supplierId));
    }
    /**
     * @author Clh
     * @description 新增类别
     * @date  2020/11/25 19:41
     * @param
     * @param
     * @return com.shop.model.vo.Rsp
    **/
    @PostMapping("insertSelective")
    public Rsp insertSelective(@RequestBody SupplierCategory supplierCategory,
                               @RequestHeader Integer supplierId,
                               @RequestHeader Integer userId){
       return supplierCategoryService.insertSelective(supplierCategory,supplierId,userId);
    }

    /**
     * 查询商品类别列表
     * 无分页
     */
    @RequireRoles(roles = {"supplier"})
    @PostMapping("getCategoryList")
    public Rsp getCategoryList(@RequestHeader Integer supplierId){
        return Rsp.success(supplierCategoryService.getCategoryList(supplierId));
    }
}

